#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

//range for events: from 0 to HISTO_SIZE
#define HISTO_SIZE 0x1000000

int main(int argc,char *argv[]) {
    unsigned int i,r,d;
    unsigned int *histo, *histo2;
		FILE *in=stdin,*out=stdout;
    
		if(!(histo=(unsigned int*)malloc(sizeof(unsigned int)*HISTO_SIZE))) {
				fprintf(stderr,"malloc returned zero"); exit(1);
		}
		if(!(histo2=(unsigned int*)malloc(sizeof(unsigned int)*HISTO_SIZE))) {
				fprintf(stderr,"malloc returned zero"); exit(1);
		}

    //clear both histograms
		fprintf(stderr,"init histogramms...");
    for(i=0; i<HISTO_SIZE; i++) {
				histo[i]=0;
				histo2[i]=0;
    }
		fprintf(stderr,"ok");

		int line=1;
		while(!feof(in)) {
				fscanf(in,"%d\n",&d);
//				fprintf(stderr,"line %d:%d\n",line++,d);
				histo[d]++;
		}
		
    //count how often each distance between to events occurs
    unsigned int last=0;
    for(i=0; i<HISTO_SIZE; i++) {
				if(histo[i] !=0 ) {
						int delta = ( i>last ? i-last : HISTO_SIZE-i+last);
						
						histo2[delta]++;
						last = i;

						if(histo[i] >1) histo2[0] += histo[i]-1;
				}
    }

    //output
    for(i=0; i<HISTO_SIZE; i++)
				fprintf(out,"%u %u %u\n",i,histo[i],histo2[i]);
}
